package com.learn.controller;

import com.learn.service.FlowLimitService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author DJJ_F
 * @version 1.0
 * @date 2025/08/07
 * @description ch12 sentinel
 * 流控，熔断
 */
@RestController
public class FlowLimitController {
    @Resource
    private FlowLimitService flowLimitService;

    @GetMapping("/testA")
    public String testA() {
        flowLimitService.common();
        return "------testA";
    }

    @GetMapping("/testB")
    public String testB() {
        flowLimitService.common();
        return "------testB";
    }

    /**
     * 控流效果--排队等待
     *
     * @return
     */
    @GetMapping("/testC")
    public String testC() {
        System.out.println(System.currentTimeMillis() + "      testC,排队等待");
        return "------testC";
    }

    /**
     * 熔断规则--慢比例
     * @return
     */
    @GetMapping("/testD")
    public String testD() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return "------testD";
    }

    /**
     * 熔断规则--异常
     * @return
     */
    @GetMapping("/testE")
    public String testE() {
        int age = 10/0;
        return "------testE";
    }
}
